import { defineStore } from 'pinia'
import {
  reqBannedUser,
  reqKickOutUser,
  reqResetUserPwd,
  reqUntieDisableUser
} from '@/service/module/main/system/user'
import { usePageCommonStore } from '@/store'

const useUserStore = defineStore('user', {
  state: () => ({
    imgUrl: '' //用户头像
  }),
  actions: {
    // 1.封禁账号--单数据操作
    async reqBannedUserAction(
      pageName: string,
      id: number,
      bannedTime: number
    ) {
      await reqBannedUser(id, bannedTime)
      // 更新列表
      await this.getListDataAction(pageName)
    },

    // 2.解封账号--单数据操作
    async reqUntieDisableUserAction(
      pageName: string,
      id: number,
      realPageName?: string
    ) {
      if (realPageName) pageName = realPageName
      await reqUntieDisableUser(id)
      await this.getListDataAction(pageName)
    },

    // 3.强制下线
    async reqKickOutUserAction(id: number) {
      await reqKickOutUser(id)
    },

    // 4.重置密码
    async reqResetUserPwdAction(id: number) {
      await reqResetUserPwd(id)
    },

    // 6.上传头像
    // async uploadImageAction(file) {
    //   const res = await uploadImage(file)
    //   this.imgUrl = import.meta.env.VITE_BASE_URL + res.data
    // },

    // 更新列表的方法
    getListDataAction(pageName: string) {
      usePageCommonStore().fetchPageDataAction(pageName, {
        current: 1,
        size: 10
      })
    }
  }
})

export default useUserStore
